/*
 * Implementation of checker "2.10     Redundant Null Check Detection"
 * Author: Lingyun Situ
 */
#include "CFG/InterProcedureCFG.h"
#include "P2A/PointToAnalysis.h"
#include "framework/ASTManager.h"
#include "framework/BasicChecker.h"
#include "framework/CallGraph.h"
#include "framework/Common.h"
#include "framework/Report.h"
#include <clang/AST/AST.h>
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/Expr.h>
#include <clang/AST/RecordLayout.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Frontend/ASTConsumers.h>
#include <clang/Frontend/ASTUnit.h>
#include <clang/Tooling/Tooling.h>
#include "framework/ASTManager.h"
#include "framework/Common.h"
#include <fstream>
#include <iostream>
#include <list>
#include <llvm/Support/raw_ostream.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace clang;
using namespace llvm;
using namespace clang::driver;
using namespace clang::tooling;
using namespace std;

class RedundantNullCheck : public BasicChecker {
public:
  RedundantNullCheck(ASTResource *resource, ASTManager *manager,
                     CallGraph *call_graph, Config *configure)
      : BasicChecker(resource, manager, call_graph, configure){

        };

  void check(PointToAnalysis *p2a);

private:
  void readConfig();
  void visitFromEntry();
  void checkFun(ASTFunction *caller);
  bool checkFunParents(ASTFunction *caller, int i);
  string exitNullCheck(ASTFunction *fun, string arg_str);
  string getString_of_Expr(Expr *expr);
  string pointer_analysis;
  ASTFunction *entryFunc;
  PointToAnalysis *p2a;
  PTATypeMap *ptm;
  PTAVarMap *pvm;
};
